#include "DirAnimationManager.hpp"

namespace sl
{
	namespace tmp
	{
		DirAnimationManagerS* DirAnimationManagerS::Update(float time)
		{
			for (std::map<std::string, DirAnimation*>::iterator iter = myData.begin(); iter != myData.end(); iter++)
				iter->second->Update(time);

			return this;
		}

		DirAnimationManagerS* DirAnimationManagerS::Draw(sf::RenderTexture* render)
		{
			for (std::map<std::string, DirAnimation*>::iterator iter = myData.begin(); iter != myData.end(); iter++)
				if (iter->second->HasATexture())
					if (render != NULL)
						render->Draw(*iter->second);
					else
						(*RenderScreen)()->Draw(*iter->second);

			return this;
		}

		DirAnimationManagerS* DirAnimationManagerS::Draw(sf::RenderTexture* render, sf::Shader& shader)
		{
			sf::RenderTexture img;
			for (std::map<std::string, DirAnimation*>::iterator iter = myData.begin(); iter != myData.end(); iter++)
				if (iter->second->HasATexture())
				{
					if (render != NULL)
						img.Create(render->GetWidth(), render->GetHeight());
					else
						img.Create((*RenderScreen)()->GetWidth(), (*RenderScreen)()->GetHeight());

					img.Draw(*iter->second);
					shader.SetTexture("sprite", img.GetTexture());
					shader.SetCurrentTexture("screen");
					if (render != NULL)
						render->Draw(*iter->second);
					else
						(*RenderScreen)()->Draw(*iter->second, shader);
				}

			return this;
		}
	}
}